package com.qnbc.mystery.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.qnbc.mystery.core.annotation.Log;
import com.qnbc.mystery.core.controller.BaseController;
import com.qnbc.mystery.core.domain.AjaxResult;
import com.qnbc.mystery.core.enums.BusinessType;
import com.qnbc.mystery.core.page.TableDataInfo;
import com.qnbc.mystery.core.utils.poi.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.qnbc.mystery.domain.BoxSet;
import com.qnbc.mystery.service.IBoxSetService;

/**
 * 奖盒设置
 *
 * @author guzj
 * @date 2024-03-04
 */
@RestController
@RequestMapping("/mystery/set")
public class BoxSetController extends BaseController {
    @Autowired
    private IBoxSetService boxSetService;

    /**
     * 查询奖盒设置列表
     */
    @GetMapping("/list")
    public TableDataInfo list(BoxSet boxSet) {
        startPage();
        List<BoxSet> list = boxSetService.selectBoxSetList(boxSet);
        return getDataTable(list);
    }

    /**
     * 导出奖盒设置列表
     */
    @Log(title = "奖盒设置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BoxSet boxSet) {
        List<BoxSet> list = boxSetService.selectBoxSetList(boxSet);
        ExcelUtil<BoxSet> util = new ExcelUtil<BoxSet>(BoxSet.class);
        util.exportExcel(response, list, "奖盒设置数据");
    }

    /**
     * 获取奖盒设置详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(boxSetService.selectBoxSetById(id));
    }

    /**
     * 新增奖盒设置
     */
    @Log(title = "奖盒设置", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BoxSet boxSet) {
        return toAjax(boxSetService.insertBoxSet(boxSet));
    }

    /**
     * 修改奖盒设置
     */
    @Log(title = "奖盒设置", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BoxSet boxSet) {
        return toAjax(boxSetService.updateBoxSet(boxSet));
    }

    /**
     * 删除奖盒设置
     */
    @Log(title = "奖盒设置", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(boxSetService.deleteBoxSetByIds(ids));
    }
}
